<?php

set_include_path(realpath('../library/') . PATH_SEPARATOR . get_include_path());

include_once 'Spt/Stream/View.php';
include_once 'Spt/View.php';

// Set view stream handler options

/**
 * @see Zend_Cache_Frontend_File
 * You cannot set "master_file"
 */
Spt_Stream_View::setCachefrontEnd(array(
    //'caching' => false // no cache while testing
));

/**
 * @see Zend_Cache_Backend
 */
Spt_Stream_View::setCacheBackEnd('File', array(
    'cache_dir' => realpath('./cache')));

/**
 * set replacement to apply to source. Here the default.
 * 
 * 1. Transform tags tags
 */
Spt_Stream_View::$globalPatterns = array(
    '/<\?=\s*/' => '<?php echo ',
	'/<\?(?!(php|xml))\s*/' => '<?php ', 
    //'/<\%=\s*/' => '<?php echo ', // you could use asp type tag in your template
    //'/<\%\s*/' => '<?php '
);
/**
 * 2. extract php code...
 */
Spt_Stream_View::$embeddedCodePattern = array(
    '/(<\?php)(.*?)(\?>)/s'); // You should have any raison to change
/**
 * 3. ...and transform it
 */
Spt_Stream_View::$patterns = array(
    '/(?<!\\\)@\$/' => '$this->', // Add your own syntax
    '/(?<!\\\)@/' => '$this->',
    '/\\\@\$/' => '@$', 
    '/\\\@/' => '@');



// set View
$view = new Spt_View(array());
$view->setEncoding('UTF-8');
$view->setScriptPath(realpath('./'));

$view->assign('title',
	'Search <span style="font-size:0.4em; display: block;"> Out of order (we are looking for the bug)',
    false // Shouldn't br escaped 
);

if (isset($_GET['search'])) {
    $view->search = $_GET['search']; // will be escape
} else {
    $view->search = '';
}

$view->assign('code', highlight_file('view://test.php', true), false);

echo $view->render('test.php');